﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-06-08 16:43:34
// 负责人：Sushee
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
using OF.Component.DTO;

namespace OF.Component.DAL
{
	
	/// <summary>
	///数据行为统计 数据访问层
	/// </summary>	
	internal partial class UserDataStatistics
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个数据行为统计
    	/// </summary>
        public UserDataStatisticsInfo QuerySingle(Expression<Func<UserDataStatisticsInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取数据行为统计列表
    	/// </summary>
	    public IList<UserDataStatisticsInfo> QueryList(Expression<Func<UserDataStatisticsInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 获取点赞用户信息
        /// </summary>
        /// <param name="postId"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public List<PostDetailLikeUserDto> GetPostLikeShopInfoByPostIdAndDataType(int postId,int dataType)
        {
            List<PostDetailLikeUserDto> list = new List<PostDetailLikeUserDto>();
            string sql = @"SELECT b.ShopID, b.UserName,b.ShopName from UserDataStatistics a
                            INNER JOIN Shop b
                            ON a.ShopID = b.ShopID where a.DataID = @PostId and a.StatisticsType = 1 and DataTypeID = @dataType";
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(sql);

            db.AddInParameter(dbc, "@PostId", DbType.Int32, postId);
            db.AddInParameter(dbc, "@dataType", DbType.Int32, dataType);
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                while (dr.Read())
                {
                    //string info = string.Format("{0}({1})", dr["UserName"].ToString(), dr["ShopName"].ToString());
                    //list.Add(info);
                    var info = SQLServerProvider.Create<PostDetailLikeUserDto>(dr);
                    list.Add(info);
                }
            }
           
            return list;
        }
		
	}
	
}